package com.example.batch;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BatchDemo {
	public static void main(String[] args) throws JobExecutionAlreadyRunningException, JobRestartException,
			JobInstanceAlreadyCompleteException, JobParametersInvalidException {
		ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
				"classpath*:/spring/*Beans.xml");
		JobLauncher jobLauncher = classPathXmlApplicationContext.getBean(JobLauncher.class);
		JobRepository jobRepository = classPathXmlApplicationContext.getBean(JobRepository.class);
		Job job = classPathXmlApplicationContext.getBean("job1", Job.class);
        // 启动任务
        jobLauncher.run(job, new JobParameters());
	}
}
